<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>计算圆的面积和周长</title>
	</head>
	<body>
		<p>半径：</p>
		<input type="text" id="n1" />
		<br />
		<br />
		<p>
		<input id="btn1" type="button" value="周长" onclick="c()" />
		<input id="btn2" type="button" value="面积" onclick="s()" />
		</p>
		<p id="r"></p>
		<script>
			function c(){
				var num1=document.getElementById("n1");//object
				var result=document.getElementById("r");
				//num1.value代表内容（String）,trim()表示去除String的前后空格;
				
				if(!Boolean(num1.value.trim())){
					alert("您还未输入");
					return;
				}
				if(isNaN(num1.value)){
					alert("输入不合法，非数字型");
				}else{
					result.innerHTML=Number(num1.value)*2*3.14;
				}
			}
			function s(){
				var r=document.getElementById("r");
				var outcome=document.getElementById("outcome");
				var result=Number(r.value)*Number(r.value)*3.14;
				if(r.value<=0){
					alert("请输入圆的半径");
				}else if(isNaN(result)){
					alert("请输入数字");
				}else{
					outcome.innerHTML=result;
				}
			}
		</script>
	</body>
</html>
